package com.example.guavaSrudy.basicSplitter;

import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;

public class GuavaBasicUse {

    public static void main(String[] args) {
//        splitString();
//        splitStringUseGuava();
//        testMapSplitter();
        Integer a = 10;
        String b = "10";
        System.out.println(a.equals(Integer.parseInt(b)));

    }
//    来看看JAVA的string原生方法操作
    public static void splitString() {
        String testString = "Monday,Tuesday,,Thursday,Friday,,";
        //parts is [Monday, Tuesday, , Thursday,Friday]
        String[] parts = testString.split(",");
        for (String s : parts) {
            System.out.println(s);
        }
    }
// 使用guara来操作,有很多链式操作
    public static void splitStringUseGuava() {
        String testString = "  Monday #@$@Tuesday,,Thursday,Friday,,";
        Iterable<String> split = Splitter.on(",").omitEmptyStrings().trimResults().split(testString);
        System.out.println(split);
    }
    /**
     * 定义一个expectedString
     * 然后Splitter把expectedString用#分割成键值对，=分割的作为键和值
     *
     */
    public static void testMapSplitter() {
        String expectedString = "Washington D.C=Redskins#New York City=Giants#Philadelphia=Eagles#Dallas=Cowboys";
        Map<String,String> testMap = Maps.newLinkedHashMap();
        testMap.put("Washington D.C","Redskins");
        testMap.put("New York City","Giants");
        testMap.put("Philadelphia","Eagles");
        testMap.put("Dallas","Cowboys");
        Map returnedString = Splitter.on("#").
                withKeyValueSeparator("=").split(expectedString);
        System.out.println(returnedString);
    }
}
